<?php
class Tag{
	public $tag =array(
		'objlist'=>array('block'=>1,'level'=>3)
	);

	public function _objlist($attr,$content){
		//显示条数
		$row = isset($attr['row'])?$attr['row']:10;
		//显示类型 hot 热门文章   new  最新文章
		$type = isset($attr['type'])?$attr['type']:'new';
		//标题长度
		$namelen = isset($attr['namelen'])?intval($attr['namelen']):50;
		$namelen = $namelen==0?50:$namelen;
		$php=<<<str
	<?php
		\$db=M("object");
		switch('$type'){
			case 'hot':
				\$db->order('count desc');
			break;
			default:
				\$db->order('oid desc');
		}
		\$result= \$db->limit($row)->all();
		if(\$result):
		foreach(\$result as \$field):
		\$field['name'] = mb_substr(\$field['name'],0,$namelen,'utf8');
		?>
str;
		$php.=$content;
		$php.="<?php endforeach;endif;?>";
		return $php;
	}
}